package cn.jdk.aqstool;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

/**
 * @author summit
 * @since 2021/8/8 20:08
 */
@Slf4j
public class Task1 implements Runnable {
	private CountDownLatch latch;

	public Task1(CountDownLatch latch) {
		this.latch = latch;
	}


	@Override
	public void run() {
		log.info("准备去完成任务1");
		try {
			TimeUnit.SECONDS.sleep(2);
			log.info("任务1已经完成");
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			// 对计数器 -1
			latch.countDown();
		}

	}
}
